*******************************************************************************
*
* CODE TO REPLICATE GALLUP GRAPH, 1997-2021 
* "GLOBAL WARMING ATTITUDES FROZEN SINCE 2016", APRIL 5, 2021
* https://news.gallup.com/poll/343025/global-warming-attitudes-frozen-2016.aspx
* GRAPH "VIEWS THAT EFFECTS OF GLOBAL WARMING HAVE ALREADY BEGUN"
*
* FOR PAPER: 
* Learning from Shared News: When Abundant Information Leads to Belief Polarization
* Bowen, Dmitriev, Galperti
* Quarterly Journal of Economics
*******************************************************************************

******************************
* LOAD DATA
******************************
use "${data}\GPSS Environment Final GA Aggregate.dta", clear

******************************
* DATA CLEANING
******************************
** Dummy for "Global Warming Has Already Begun"
gen gw_when_already = (gw_when == 1)
	* Replace gw_when_already as missing for all of original variable's missing values
	replace gw_when_already = . if missing(gw_when)

** Dummies for political party (independents include lean republican and lean democrat)	
tab partyrr, gen(party2)
	
	* Renaming dummies
	rename party21 reprr
	rename party22 indeprr
	rename party23 demrr
	
	drop party24

** Append in 1997 data
append using "${data}\gallup1997_forappend.dta"

** Multiply the partyrr dummies by population weights to get weighted observations
foreach var of varlist reprr indeprr demrr {
	gen `var'_wt = `var'*wtfctr
	
	gen `var'_wt_already = `var'_wt*gw_when_already
}

******************************
* COLLAPSE
******************************
** Sum over all weighted political party counts to get weighted N for all political parties and totals for number of people who believe global warming has already begun
collapse (sum) *rr_wt*, by(yr)

** Create percentages of the obs by party that think that global warming has already begun
loc varlist reprr indeprr demrr 
foreach var in `varlist' {
	gen `var'_perc_already = (`var'_wt_already/`var'_wt)*100
	
	* 2000 has 0 across the board because no one was asked this question in 2000. Replace with missings
	replace `var'_perc_already = . if yr == 2000
}

******************************
* GRAPH AND EXPORT
******************************
graph twoway (line reprr_perc_already yr if yr < 2022, lcolor(red)) ///
			 (line indeprr_perc_already yr if yr < 2022, lpattern(shortdash_dot) lcolor(gray)) ///
			 (line demrr_perc_already yr if yr < 2022, lpattern(dash) lcolor(blue)), ///
			 ylabel(10(10)90) ytitle(Percent) ///
			 xlabel(1997(2)2021) xtitle(Year) ///
			 legend(order(1 "Republicans" 2 "Independents" 3 "Democrats")) ///
			 graphregion(color(white)) bgcolor(white) plotregion(margin(0)) ///
			 note("Source: Gallup Poll Social Series, 1997-2021")
			 
graph export "${output}\global_warming_gallup.png", as(png) replace

exit